package com.example.yuejian.yuejian.adapter;


import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.activity.OrderActivity;
import com.example.yuejian.yuejian.bean.Order;

import java.util.List;

/**
 * Created by Administrator on 2017/9/18.
 */

public class MyOrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
{
    private Context mContext;;
    private List mDataList;
    public LayoutInflater mLayoutInflater;
    public MyOrderAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.inflate(R.layout.cardview_my_order, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Order entity = (Order) mDataList.get(position);
        if (null == entity)
            return;
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.myorder_name.setText(entity.getTrainname());
        viewHolder.myorder_price.setText("订单总额"+entity.getMoney()+"元");
        if (entity.getState()==0)
        {
            viewHolder.myordre_state.setText("待参加");
        }
        else {
            viewHolder.myordre_state.setText("已完成");
        }
       /* if(!"".equals(entity.getTrainphoto()))
        {
            Picasso.with(mContext).load(entity.getTrainphoto()).into(viewHolder.imageView_photo);
        }
        else
        {
            viewHolder.imageView_photo.setImageResource(R.drawable.camera);
        }*/



viewHolder.myorder_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext, OrderActivity.class);
                intent.putExtra("order_id",entity.getId()+"");
                mContext.startActivity(intent);

            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView myorder_name;

        TextView myorder_price;
        TextView myordre_state;

       // ImageView imageView_photo;
        LinearLayout myorder_detail;

        public ViewHolder(View itemView) {
            super(itemView);

            myorder_name = (TextView) itemView.findViewById(R.id.tv_my_order_name);

            myordre_state = (TextView) itemView.findViewById(R.id.tv_my_order_stutas);
            myorder_price = (TextView) itemView.findViewById(R.id.tv_my_order_price);
            //imageView_photo=(ImageView)itemView.findViewById(R.id.img_my_order_photo);
            myorder_detail=(LinearLayout)itemView.findViewById(R.id.cardview_my_order_content);

        }
    }

}
